<!DOCTYPE html>
<html lang="en">
<title>企业储值卡管理</title>
<#import "/layout/layout.html" as body/>

<@body.page>
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>企业储值卡管理</h2>
        <ol class="breadcrumb">
            <li><a href="#">企业储值账户列表</a></li>
            <li class="active"><strong>订单列表</strong></li>
        </ol>
    </div>
</div>
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title overflow">
                    <h5 class="pull-left">订单列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="table-responsive">
                        <form  class="form-inline" id="form">
                            <input type="hidden" id="companyId" value="${companyId}" />
                            <div class="form-group">
                                <label>姓名：</label>
                                <input class="form-control" type="text" id="name" name="name"/>
                            </div>
                            <div class="form-group">
                                <label>手机号：</label>
                                <input class="form-control" min="13000000000" type="number" id="mobile" name="mobile"/>
                            </div>
                            <div class="form-group">
                                <label for="status">状态：</label>
                                <select class="form-control" id="status" name="status">
                                    <option value="">全部</option>
                                    <option value="0">正常</option>
                                    <option value="1">已取消</option>
                                    <option value="2">已退款</option>
                                    <option value="4">已完成</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="year">年份：</label>
                                <select class="form-control" id="year" name="year">
                                    <option value="">全部</option>
                                    <option value="2017">2017</option>
                                    <option value="2018">2018</option>
                                    <option value="2019">2019</option>
                                    <option value="2019">2019</option>
                                    <option value="2020">2020</option>
                                    <option value="2021">2021</option>
                                    <option value="2022">2022</option>
                                    <option value="2023">2023</option>
                                    <option value="2024">2024</option>
                                    <option value="2025">2025</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label for="month">月份：</label>
                                <select class="form-control" id="month" name="month">
                                    <option value="">全部</option>
                                    <option value="1">1月</option>
                                    <option value="2">2月</option>
                                    <option value="3">3月</option>
                                    <option value="4">4月</option>
                                    <option value="5">5月</option>
                                    <option value="6">6月</option>
                                    <option value="7">7月</option>
                                    <option value="8">8月</option>
                                    <option value="9">9月</option>
                                    <option value="10">10月</option>
                                    <option value="11">11月</option>
                                    <option value="12">12月</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>订单号：</label>
                                <input class="form-control" type="number" id="orderNumber" name="orderNumber"/>
                            </div>
                            <button type="button" onclick="orderPage(1)" class="btn btn-outline btn-primary" style="margin-top: 5px">确认</button>
                        </form>
                        <hr style="width: 100%">
                        <table class="table table-hover table-center dataTables-example">
                            <thead>
                            <tr>
                                <!--<th>序号</th>-->
                                <th>订单号</th>
                                <th>购买类型</th>
                                <th>支付时间</th>
                                <th>消费员工</th>
                                <th>门店</th>
                                <th>费用</th>
                                <th>优惠券</th>
                                <th>实付</th>
                                <th>状态</th>
                            </tr>
                            </thead>
                            <tbody id="list">
                            <tr>
                                <!--<td>1</td>-->
                            </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
                <div class="ibox-footer overflow">
                    <div class="col-sm-12 padding-left-0">
                        <h4 class="pull-left">合计：<span id="count">0</span>笔订单</h4>
                        <div id="copot-page" class="pull-right"></div>
                    </div>
                    <button type="button" id="go_back_list" class="btn btn-primary pull-left">返回企业列表</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="${baseUrl}js/main.js"></script>
<script>
    $(document).ready(function () {
        orderPage(1);
    });
    //返回列表
    $('#go_back_list').click(function () {
        window.location = "${baseUrl}system/company/list";
    });
    /**
     * 企业已完成订单列表
     *
     * @param currentIndex 页码
     */
    function orderPage(currentIndex) {
        var param = {
            "pageIndex": currentIndex,
            "pageSize": 10,
            "name": $("#name").val(),
            "mobile": $("#mobile").val(),
            "orderStatus": $("#status").val(),
            "year": $("#year").val(),
            "month": $("#month").val(),
            "orderNumber": $("#orderNumber").val(),
            "companyId": $("#companyId").val()
        };
        $.post("${baseUrl}system/company/companyOrderList", param, function (result) {
            console.log("JSON " + result);
            result = JSON.parse(result);
            console.log("JSON.parse后" + result);
            //分页
            console.log("-------");
            new Page({
                parent: $("#copot-page"),
                nowPage: currentIndex,
                pageSize: 10,
                totalCount: result.count,
                setting: {
                    defaultPage: 5,//默认显示可点击分页的个数
                    firstPageText: "首页",
                    prevPageText: "上一页",
                    nextPageText: "下一页",
                    lastPageText: "尾页"
                },
                callback: function (nowPage, totalPage) {
                    orderPage(nowPage);
                }
            });

            $("#count").text(result.count);

            var html = "";
            var couponDetailId;
            var status;
            var courseVipPrice;
            $.each(result.list, function (i, data) {
                if (data) {
                    if (data.orderStatus >= 0) {
                        debugger
                        if (data.orderStatus == 1) {
                            status = "正常"
                        } else if (data.orderStatus == 2 && (data.payStatus == 1 || data.payStatus == 3 )) {
                            status = "已取消"
                        } else if (data.orderStatus == 2 && data.payStatus == 4) {
                            status = "已退款"
                        } else if (data.orderStatus == 2 && data.payStatus == 5) {
                            status = "部分退款"
                        } else if (data.orderStatus == 3) {
                            status = "排队"
                        } else if (data.orderStatus == 4 && (data.payStatus == 1 || data.payStatus == 3 )) {
                            status = "已完成"
                        } else {
                            status = "数据异常"
                        }
                    }
                    if(data.couponDetailId >0){
                        couponDetailId = data.couponDetailId
                    } else {
                        couponDetailId = "无"
                    }
                    if(data.courseVipPrice >=0){
                        courseVipPrice = data.courseVipPrice;
                    } else {
                        courseVipPrice = "无";
                    }
                }
                html += "<tr><td>" + data.orderNumber + "</td>";
                var amount = "";
                if(data.orderType == 4){
                    html += "<td>自助健身</td>";
                } else if(data.orderType !=5){
                    html += "<td>" + data.courseTitle + "(" + data.courseId + ")</td>";
                } else if(data.orderType == 5) {
                    html += "<td>会员充值"  + "(" + data.vipMonth + "个月)</td>";
                } else if(data.orderType == 6){
                    html += "<td>储值卡充值</td>";
                }

                html += "<td>" + data.payTime + "</td>";
                html += "<td>" + data.name + "<br>"+ data.mobile + "</td>";
                if(data.orderType == 5 || data.orderType == 6){
                    html += "<td>/</td>";
                } else {
                    html += "<td>" + data.storeName + "</td>";
                }
                if(data.orderType == 5){
                    html += "<td>¥" + data.amount + "</td>";
                } else {
                    html += "<td>¥" + data.coursePrice + "会员价(¥" + courseVipPrice + ")</td>";
                }

                if(data.couponDetailId >0){
                    html += "<td>¥" + data.couponMoney + "(" + data.couponDetailId +  ")</td>";
                } else {
                    html += "<td>无</td>";
                }
                
                if(data.weixinAmt > 0){
                	amount = data.amount+"(微_"+data.weixinAmt+"/企_"+data.companyAmt+")";
                }else{
                	amount = data.amount;
                }
                html += "<td>¥" + amount +"</td>";
                html += "<td>" + status + "</td>";
                html += "</tr>";
            });
            $("#list").html(html);

        });
    }

</script>
</@body.page>
</html>